#!/usr/bin/env python
# encoding: utf-8
"""
untitled.py

Created by David Wagner on 2009-07-14.
Copyright (c) 2009 __MyCompanyName__. All rights reserved.
"""

import sys
import getopt
import ConfigParser
import os

config      = ConfigParser.SafeConfigParser()
config_path = "./istan.config"

help_message = '''
The help message goes here.
'''


class Usage(Exception):
	def __init__(self, msg):
		self.msg = msg

def initConfig():
	"""docstring for initConfig"""
	config.read( config_path )

def exportScummVM():
	svn = "svn export https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/" + config.get( "ScummVM", "tag" ) + " " + config.get( "ScummVM", "scummvm_export_dir" )
	os.system( svn )

def main(argv=None):
	if argv is None:
		argv = sys.argv
	try:
		try:
			opts, args = getopt.getopt(argv[1:], "ho:v", ["help", "output="])
		except getopt.error, msg:
			raise Usage(msg)
	
		# option processing
		for option, value in opts:
			if option == "-v":
				verbose = True
			if option in ("-h", "--help"):
				raise Usage(help_message)
			if option in ("-o", "--output"):
				output = value
		
		# do stuff
		initConfig();
		
		exportScummVM()
	
	except Usage, err:
		print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
		print >> sys.stderr, "\t for help use --help"
		return 2


if __name__ == "__main__":
	sys.exit(main())
